package com.globo.opensocial;

import org.htmlparser.tags.ImageTag;

public class ImageProxy {

	String host = null;
	Parser parser = null;

	public ImageProxy(String host, Parser parser) {
		this.host = host;
		this.parser = parser;
	}

	public void append(ImageTag imageTag, StringBuilder out) {

		String src = imageTag.getAttribute("src");
		if (src == null) {
			// TODO: ERRO!
		}
		out.append(" = osg.imgProxy(\"");
		if (!src.startsWith("http://") && src.matches("^[a-zA-Z_].*")) {
			out.append(host);
			out.append("/");
			out.append(parser.filterText(src));
		} else {
			out.append(parser.filterText(src));
		}
		out.append("\");\n");
	}

}
